Imports System.Drawing

Namespace Overlay
    Friend Class IndicatorFactory
        Public Sub Draw( _
            ByVal oIndicator As Indicator, _
            ByVal g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer)

            Draw( _
                oIndicator:=oIndicator, _
                g:=g, _
                iXPos:=iXPos, _
                iYPos:=iYPos, _
                iDiameterWidth:=oIndicator.IndicatorWidth, _
                iDiameterHeight:=oIndicator.IndicatorHeight, _
                iOpacity:=oIndicator.Opacity)
        End Sub

        Public Sub Draw( _
            ByVal oIndicator As Indicator, _
            ByVal g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal iOpacity As Single)

            Draw( _
                oIndicator:=oIndicator, _
                g:=g, _
                iXPos:=iXPos, _
                iYPos:=iYPos, _
                iDiameterWidth:=oIndicator.IndicatorWidth, _
                iDiameterHeight:=oIndicator.IndicatorHeight, _
                iOpacity:=iOpacity)
        End Sub

        Public Sub Draw( _
            ByVal oIndicator As Indicator, _
            ByVal g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal iDiameter As Integer)

            Draw( _
                oIndicator:=oIndicator, _
                g:=g, _
                iXPos:=iXPos, _
                iYPos:=iYPos, _
                iDiameterWidth:=iDiameter, _
                iDiameterHeight:=iDiameter, _
                iOpacity:=oIndicator.Opacity)
        End Sub

        Public Sub Draw( _
            ByVal oIndicator As Indicator, _
            ByVal g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal iDiameterWidth As Integer, _
            ByVal iDiameterHeight As Integer, _
            ByVal iOpacity As Single)

            Dim iARGB As Single = iOpacity * 255

            Dim oSemiTransparentColor As Color = System.Drawing.Color.FromArgb(iARGB, oIndicator.Color.R, oIndicator.Color.G, oIndicator.Color.B)
            Dim oRect3 As New Rectangle(iXPos - iDiameterWidth / 2, iYPos - iDiameterHeight / 2, iDiameterWidth, iDiameterHeight)
            Dim oRect1 As Rectangle = New Rectangle(oRect3.X + 3, oRect3.Y + 3, oRect3.Width - 6, oRect3.Height - 6)

            Select Case oIndicator.IndicatorType
                Case Indicator.Type.Box
                    DrawBox(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)

                Case Indicator.Type.Rectangle
                    DrawRectangle(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)

                Case Indicator.Type.Circle
                    DrawCircle(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)

                Case Indicator.Type.Cross
                    DrawCross(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)

                Case Indicator.Type.DownArrow
                    DrawDownArrow(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)

                Case Indicator.Type.LeftArrow
                    DrawLeftArrow(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)

                Case Indicator.Type.RightArrow
                    DrawRightArrow(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)

                Case Indicator.Type.UpArrow
                    DrawUpArrow(oIndicator, g, iXPos, iYPos, oSemiTransparentColor, oRect3, oRect1)
            End Select
        End Sub

        Private Sub DrawCircle( _
                    ByVal oIndicator As Indicator, _
                    ByRef g As Graphics, _
                    ByVal iXPos As Integer, _
                    ByVal iYPos As Integer, _
                    ByVal oColor As Color, _
                    ByVal oRect3 As Rectangle, _
                    ByVal oRect1 As Rectangle)

            Dim iARGB As Integer = oColor.A
            If iARGB < 255 Then
                iARGB = iARGB * 1.25
                If iARGB > 255 Then iARGB = 255
            End If

            Dim oOuterColor As Color = System.Drawing.Color.FromArgb(iARGB, oIndicator.Color.R, oIndicator.Color.G, oIndicator.Color.B)

            g.FillEllipse(New SolidBrush(oOuterColor), oRect3)
            g.FillEllipse(New SolidBrush(System.Drawing.Color.White), oRect1)
            g.FillEllipse(New SolidBrush(oColor), oRect3)

            g.DrawEllipse(Pens.Black, oRect3)
        End Sub

        Private Sub DrawBox( _
                ByVal oIndicator As Indicator, _
                ByRef g As Graphics, _
                ByVal iXPos As Integer, _
                ByVal iYPos As Integer, _
                ByVal oColor As Color, _
                ByVal oRect3 As Rectangle, _
                ByVal oRect1 As Rectangle)

            g.FillRectangle(New SolidBrush(System.Drawing.Color.Black), oRect3)
            g.FillRectangle(New SolidBrush(System.Drawing.Color.White), oRect1)
            g.FillRectangle(New SolidBrush(oColor), oRect3)

            g.DrawRectangle(Pens.Black, oRect3)
        End Sub

        Private Sub DrawRectangle( _
            ByVal oIndicator As Indicator, _
            ByRef g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal oColor As Color, _
            ByVal oRect3 As Rectangle, _
            ByVal oRect1 As Rectangle)

            Dim oRect1a As New Rectangle( _
                                    oRect1.X, _
                                    oRect1.Y + oRect1.Height / 4, _
                                    oRect1.Width, _
                                    oRect1.Height / 2)

            Dim oRect3a As New Rectangle( _
                                    oRect3.X, _
                                    oRect3.Y + oRect3.Height / 4, _
                                    oRect3.Width, _
                                    oRect3.Height / 2)

            g.FillRectangle(New SolidBrush(System.Drawing.Color.Black), oRect3a)
            g.FillRectangle(New SolidBrush(System.Drawing.Color.White), oRect1a)
            g.FillRectangle(New SolidBrush(oColor), oRect3a)

            g.DrawRectangle(Pens.Black, oRect3a)
        End Sub

        Private Sub DrawUpArrow( _
            ByVal oIndicator As Indicator, _
            ByRef g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal oColor As Color, _
            ByVal oRect3 As Rectangle, _
            ByVal oRect1 As Rectangle)

            Dim oPoints1(2) As Point
            Dim oPoints3(2) As Point

            oPoints1(0).X = (oRect3.X + 1) + (oRect3.Width - 2) / 2
            oPoints1(0).Y = oRect3.Y + 1

            oPoints1(1).X = oRect3.X + 1
            oPoints1(1).Y = (oRect3.Y + 1) + (oRect3.Height - 2)

            oPoints1(2).X = oRect3.X + 1 + (oRect3.Width - 2)
            oPoints1(2).Y = (oRect3.Y + 1) + (oRect3.Height - 2)

            oPoints3(0).X = oRect3.X + oRect3.Width / 2
            oPoints3(0).Y = oRect3.Y

            oPoints3(1).X = oRect3.X
            oPoints3(1).Y = oRect3.Y + oRect3.Height

            oPoints3(2).X = oRect3.X + oRect3.Width
            oPoints3(2).Y = oRect3.Y + oRect3.Height

            g.FillPolygon(New SolidBrush(System.Drawing.Color.Black), oPoints3)
            g.FillPolygon(New SolidBrush(System.Drawing.Color.White), oPoints1)
            g.FillPolygon(New SolidBrush(oColor), oPoints3)

            g.DrawPolygon(Pens.Black, oPoints3)
        End Sub

        Private Sub DrawDownArrow( _
            ByVal oIndicator As Indicator, _
            ByRef g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal oColor As Color, _
            ByVal oRect3 As Rectangle, _
            ByVal oRect1 As Rectangle)

            Dim oPoints1(2) As Point
            Dim oPoints3(2) As Point

            '---Middle of triangle
            oPoints1(0).X = (oRect3.X + 1) + (oRect3.Width - 2) / 2
            oPoints1(0).Y = (oRect3.Y + 1) + (oRect3.Height - 2)

            '---Left side
            oPoints1(1).X = oRect3.X + 1
            oPoints1(1).Y = oRect3.Y + 1

            '---Right side
            oPoints1(2).X = oRect3.X + 1 + (oRect3.Width - 2)
            oPoints1(2).Y = oRect3.Y + 1

            '---Middle of triangle
            oPoints3(0).X = oRect3.X + oRect3.Width / 2
            oPoints3(0).Y = oRect3.Y + oRect3.Height

            '---Left side
            oPoints3(1).X = oRect3.X
            oPoints3(1).Y = oRect3.Y + 1

            '---Right side
            oPoints3(2).X = oRect3.X + oRect3.Width
            oPoints3(2).Y = oRect3.Y + 1

            g.FillPolygon(New SolidBrush(System.Drawing.Color.Black), oPoints3)
            g.FillPolygon(New SolidBrush(System.Drawing.Color.White), oPoints1)
            g.FillPolygon(New SolidBrush(oColor), oPoints3)

            g.DrawPolygon(Pens.Black, oPoints3)
        End Sub

        Private Sub DrawLeftArrow( _
            ByVal oIndicator As Indicator, _
            ByRef g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal oColor As Color, _
            ByVal oRect3 As Rectangle, _
            ByVal oRect1 As Rectangle)

            Dim oPoints1(2) As Point
            Dim oPoints3(2) As Point

            '---Middle of triangle
            oPoints1(0).X = oRect3.X + 1
            oPoints1(0).Y = (oRect3.Y + 1) + ((oRect3.Height - 2) / 2)

            '---Top right
            oPoints1(1).X = oRect3.X + 1 + (oRect3.Width - 2)
            oPoints1(1).Y = oRect3.Y + 1

            '---Bottom right
            oPoints1(2).X = oRect3.X + 1 + (oRect3.Width - 2)
            oPoints1(2).Y = oRect3.Y + oRect3.Height



            '---Middle of triangle
            oPoints3(0).X = oRect3.X
            oPoints3(0).Y = oRect3.Y + (oRect3.Height / 2)

            '---Top right
            oPoints3(1).X = oRect3.X + oRect3.Width
            oPoints3(1).Y = oRect3.Y + 1

            '---Bottom right
            oPoints3(2).X = oRect3.X + oRect3.Width
            oPoints3(2).Y = oRect3.Y + oRect3.Height



            g.FillPolygon(New SolidBrush(System.Drawing.Color.Black), oPoints3)
            g.FillPolygon(New SolidBrush(System.Drawing.Color.White), oPoints1)
            g.FillPolygon(New SolidBrush(oColor), oPoints3)

            g.DrawPolygon(Pens.Black, oPoints3)
        End Sub

        Private Sub DrawRightArrow( _
            ByVal oIndicator As Indicator, _
            ByRef g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal oColor As Color, _
            ByVal oRect3 As Rectangle, _
            ByVal oRect1 As Rectangle)

            Dim oPoints1(2) As Point
            Dim oPoints3(2) As Point

            '---Middle of triangle
            oPoints1(0).X = oRect3.X + 1 + (oRect3.Width - 2)
            oPoints1(0).Y = (oRect3.Y + 1) + ((oRect3.Height - 2) / 2)

            '---Top left
            oPoints1(1).X = oRect3.X + 1
            oPoints1(1).Y = oRect3.Y + 1

            '---Bottom left
            oPoints1(2).X = oRect3.X + 1
            oPoints1(2).Y = oRect3.Y + oRect3.Height



            '---Middle of triangle
            oPoints3(0).X = oRect3.X + oRect3.Width
            oPoints3(0).Y = oRect3.Y + (oRect3.Height / 2)

            '---Top left
            oPoints3(1).X = oRect3.X
            oPoints3(1).Y = oRect3.Y + 1

            '---Bottom left
            oPoints3(2).X = oRect3.X
            oPoints3(2).Y = oRect3.Y + oRect3.Height



            g.FillPolygon(New SolidBrush(System.Drawing.Color.Black), oPoints3)
            g.FillPolygon(New SolidBrush(System.Drawing.Color.White), oPoints1)
            g.FillPolygon(New SolidBrush(oColor), oPoints3)

            g.DrawPolygon(Pens.Black, oPoints3)
        End Sub

        Private Sub DrawCross( _
            ByVal oIndicator As Indicator, _
            ByRef g As Graphics, _
            ByVal iXPos As Integer, _
            ByVal iYPos As Integer, _
            ByVal oColor As Color, _
            ByVal oRect3 As Rectangle, _
            ByVal oRect1 As Rectangle)

            Dim oPoints1(11) As Point
            Dim oPoints3(11) As Point

            oPoints1(0).X = oRect3.X + 1
            oPoints1(0).Y = oRect3.Y + (oRect3.Height / 3) + 1

            oPoints1(1).X = oRect3.X + oRect3.Width / 3 + 1
            oPoints1(1).Y = oRect3.Y + (oRect3.Height / 3) + 1

            oPoints1(2).X = oRect3.X + oRect3.Width / 3 + 1
            oPoints1(2).Y = oRect3.Y

            oPoints1(3).X = oRect3.X + 2 * (oRect3.Width / 3) - 1
            oPoints1(3).Y = oRect3.Y + 1

            oPoints1(4).X = oRect3.X + 2 * (oRect3.Width / 3) - 1
            oPoints1(4).Y = oRect3.Y + (oRect3.Height / 3) + 1

            oPoints1(5).X = oRect3.X + oRect3.Width - 1
            oPoints1(5).Y = oRect3.Y + (oRect3.Height / 3) + 1

            oPoints1(6).X = oRect3.X + oRect3.Width - 1
            oPoints1(6).Y = oRect3.Y + 2 * (oRect3.Height / 3) - 1

            oPoints1(7).X = oRect3.X + 2 * (oRect3.Width / 3) - 1
            oPoints1(7).Y = oRect3.Y + 2 * (oRect3.Height / 3) - 1

            oPoints1(8).X = oRect3.X + 2 * (oRect3.Width / 3) - 1
            oPoints1(8).Y = oRect3.Y + oRect3.Height - 1

            oPoints1(9).X = oRect3.X + (oRect3.Width / 3) + 1
            oPoints1(9).Y = oRect3.Y + oRect3.Height - 1

            oPoints1(10).X = oRect3.X + (oRect3.Width / 3) + 1
            oPoints1(10).Y = oRect3.Y + 2 * (oRect3.Height / 3) - 1

            oPoints1(11).X = oRect3.X + 1
            oPoints1(11).Y = oRect3.Y + 2 * (oRect3.Height / 3) - 1


            oPoints3(0).X = oRect3.X
            oPoints3(0).Y = oRect3.Y + (oRect3.Height / 3)

            oPoints3(1).X = oRect3.X + oRect3.Width / 3
            oPoints3(1).Y = oRect3.Y + (oRect3.Height / 3)

            oPoints3(2).X = oRect3.X + oRect3.Width / 3
            oPoints3(2).Y = oRect3.Y

            oPoints3(3).X = oRect3.X + 2 * (oRect3.Width / 3)
            oPoints3(3).Y = oRect3.Y

            oPoints3(4).X = oRect3.X + 2 * (oRect3.Width / 3)
            oPoints3(4).Y = oRect3.Y + (oRect3.Height / 3)

            oPoints3(5).X = oRect3.X + oRect3.Width
            oPoints3(5).Y = oRect3.Y + (oRect3.Height / 3)

            oPoints3(6).X = oRect3.X + oRect3.Width
            oPoints3(6).Y = oRect3.Y + 2 * (oRect3.Height / 3)

            oPoints3(7).X = oRect3.X + 2 * (oRect3.Width / 3)
            oPoints3(7).Y = oRect3.Y + 2 * (oRect3.Height / 3)

            oPoints3(8).X = oRect3.X + 2 * (oRect3.Width / 3)
            oPoints3(8).Y = oRect3.Y + oRect3.Height

            oPoints3(9).X = oRect3.X + (oRect3.Width / 3)
            oPoints3(9).Y = oRect3.Y + oRect3.Height

            oPoints3(10).X = oRect3.X + (oRect3.Width / 3)
            oPoints3(10).Y = oRect3.Y + 2 * (oRect3.Height / 3)

            oPoints3(11).X = oRect3.X
            oPoints3(11).Y = oRect3.Y + 2 * (oRect3.Height / 3)

            g.FillPolygon(New SolidBrush(System.Drawing.Color.Black), oPoints3)
            g.FillPolygon(New SolidBrush(System.Drawing.Color.White), oPoints1)
            g.FillPolygon(New SolidBrush(oColor), oPoints3)

            g.DrawPolygon(Pens.Black, oPoints3)
        End Sub
    End Class
End Namespace